import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'

import VueParticles from 'vue-particles';

import SvgIcon from '@/components/SvgIcon.vue'


const app = createApp(App)
app.component('svg-icon', SvgIcon)

// 自动导入所有svg文件
const req = require.context('./assets/icons/svg', false, /\.svg$/)
req.keys().forEach(req)

//设置根路径
const BASE_URL = 'http://localhost:8080';
window.BASE_URL = BASE_URL;
app.config.globalProperties.BASE_URL = BASE_URL;

app.use(VueParticles).use(ElementPlus).use(store).use(router).mount('#app')

//配置全局方法，获取当前登录人的数据
window.getUser = () => {
    return localStorage.user ? JSON.parse(localStorage.getItem('user')) : null;
}

// 解决 Element UI 组件触发的无害 ResizeObserver 警告
const debounce = (fn, delay) => {
    let timer
    return () => {
        if (timer) clearTimeout(timer)
        timer = setTimeout(() => fn(), delay)
    }
}

const _ResizeObserver = window.ResizeObserver
window.ResizeObserver = class ResizeObserver extends _ResizeObserver {
    constructor(callback) {
        callback = debounce(callback, 16)
        super(callback)
    }
}
